﻿using ELTE.SEM.Data.Connectors;
using ELTE.SEM.Data.Managers;
using ELTE.SEM.Data.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace ELTE.NPRG.WEB.Controllers
{
    public class HomeController : ControllerBase
    {
        FolderManager FolderManager { get; set; }
        ImageManager ImageManager { get; set; }

        public HomeController()
            : base()
        {
            FolderManager = new FolderManager(this.DataEntities);
            
        }

        [HttpGet]
        public ActionResult Index()
        {

            return View();
        }

        //public ActionResult ControlTest()
        //{
        //    return View();
        //}

        //public ActionResult FolderTest()
        //{
        //    SemFileServerLoginViewModel loginViewModel = GetRemoteLoginViewModel();
        //    SambaConnector connector = new SambaConnector(loginViewModel);
        //    var allFoldersAndFiles = connector.GetAllFolders();
        //    var folders = allFoldersAndFiles.Where(f => f.IsDirectory).ToList();
        //    //Manager.BulkInsert(folders, loginViewModel.HomeFolder);
        //    //if (folders.Count() > 0)
        //    //{
        //    //    SemFolderViewModel folder = Manager.GetFolderViewModel(
        //    //        new SemDataViewModel { Name = "nanocsepp", ParentFolder = "adrienn" });
        //    //    ImageManager = new ImageManager(loginViewModel);
        //    //    List<string> filePaths = ImageManager.GetFilesInFolder(folder, loginViewModel.HomeFolder);
        //    //    List<System.IO.Stream> fileStreams = new List<System.IO.Stream>();
        //    //    filePaths.ForEach(f =>
        //    //        fileStreams.Add(ImageManager.GetFileStreamAsPng(f))
        //    //        );
        //    //    if (fileStreams.Count > 0)
        //    //    {
 
        //    //    }
        //    //}
        //    try
        //    {
        //        ImageManager = new ImageManager(loginViewModel,this.DataEntities);
        //        var tiffs = allFoldersAndFiles
        //            .Where(f => !f.IsDirectory
        //                && (f.FullName.ToLower().EndsWith("tiff") || f.FullName.ToLower().EndsWith("tif"))
        //            )
        //            .ToList();
        //        if (tiffs.Count > 0)
        //        {
        //            tiffs.ForEach(tiff => ImageManager.AddScanImage(tiff, loginViewModel.HomeFolder));
        //        }
        //    }
        //    catch (Exception ex)
        //    {
                
        //    }


        //    return View();
        //}

        //[HttpGet]
        //private ActionResult SEMLog()
        //{
        //    return View();
        //}

        //private ActionResult UserManagement()
        //{
        //    return View();
        //}

        //public ActionResult GetImages() 
        //{
        //    SemFileServerLoginViewModel loginViewModel = GetRemoteLoginViewModel();
        //    SambaConnector connector = new SambaConnector(loginViewModel);
        //    var allFoldersAndFiles = connector.GetAllFolders();
        //    var folders = allFoldersAndFiles.Where(f => f.IsDirectory).ToList();
        //    try
        //    {
        //        ImageManager = new ImageManager(loginViewModel, this.DataEntities);
        //        var tiffs = allFoldersAndFiles
        //            .Where(f => !f.IsDirectory
        //                && (f.FullName.ToLower().EndsWith("tiff") || f.FullName.ToLower().EndsWith("tif"))
        //            )
        //            .ToList();
        //        if (tiffs.Count > 0)
        //        {
        //            //tiffs.ForEach(tiff => ImageManager.AddScanImage(tiff, loginViewModel.HomeFolder));
        //            ImageManager.AddScanImage(tiffs, loginViewModel.HomeFolder);
        //        }
        //    }
        //    catch (Exception ex)
        //    {

        //    }
        //    return RedirectToAction("Index");
        //}
    }
}
